package com.wendjia.demo.service.impl;

import com.sun.org.apache.regexp.internal.RE;
import com.wendjia.demo.dao.UserDao;
import com.wendjia.demo.model.User;
import com.wendjia.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by wendjia on 2017/3/8.
 */
@Component
public class UserServiceImp implements IUserService {
//    @Autowired
//    protected MongoTemplate mongoTemplate;
    @Autowired
    protected  UserDao userDao;

    public User saveUser(User user) {
       User result =  userDao.save(user);
        return result;
    }

    public List<User> findAll(){
      return   userDao.findAll();
    }

    @Override
    public User login(String name, String password) {
       User user =  userDao.findByName(name);
       if (password.equals(user.getPassword())){
           return user;
       }else {
           return null;
       }
    }
}
